<?php
namespace App\Repositories\Backend;

use App\Models\ComboBranch;
use Illuminate\Support\Facades\Auth;

class ComboBranchRepository extends CommonRepository
{

    public function __construct(ComboBranch $combobranch)
    {
        parent::__construct($combobranch);
    }


    /**
     * 新增/修改
     * @param  array  $domains    参数数组
     * @param  int    $combo_id   套餐id
     * @return object
     */
    public function branch($domains, $combo_id)
    {
        //先删除对应id的数据
        //$result = $this->deleteByWhere(['combo_id'=>$combo_id]);
        $result = $this->model->where('combo_id', $combo_id)->delete();



//        if(!$result){
//            return false;
//        }

        //插入数据
        foreach ($domains as $k=>$v){
            $result = $this->model->create([
                'combo_id' => $combo_id,
                'branch_content' => $v['branch_content'],
                'branch_title' => $v['branch_title'],
            ]);
        }

        return $result;
    }


}